<article class="" id="post-">
<header class="entry-header">
<h1 class="entry-title">.context</h1>
<div class="entry-meta">
						所属分类：<span class="category"><a href="/category/internals/">内部函数</a></span><span class="category-divider"> | </span><span class="category"><a href="/category/properties/">内部属性</a> &gt; <a href="/category/properties/jquery-object-instance-properties/">jQuery 对象实例的属性</a></span><span class="category-divider"> | </span><span class="category"><a href="/category/deprecated/">弃用</a> &gt; <a href="/category/deprecated/deprecated-1.10/">1.10 版本弃用的 API</a></span><span class="category-divider"> | </span><span class="category"><a href="/category/removed/">已删除的函数</a></span>
<span class="pull-right">英文文档：<a href="https://api.jquery123.com/context/" target="_blank">.context</a></span>
</div><!-- .entry-meta -->
</header><!-- .entry-header -->
<!-- .entry-header -->
<div class="entry-content">
<article class="entry property" id="context1"><h2 class="section-title">
<span>context</span><span class="returns">返回: <a href="/Types/#Element">Element</a></span><span class="version-details">version deprecated: <a href="/category/version/1.10/">1.10</a></span>
</h2>
<div class="entry-wrapper">
<p class="desc"><strong>描述: </strong>原始的DOM节点的内容传给<code>jQuery()</code>；如果没有东西被传递，那么上下文将可能是该文档（document）。</p>
<ul class="signatures"><li class="signature"><h4 class="name">
<span class="version-details">添加的版本: <a href="/category/version/1.3/">1.3</a></span>context</h4></li></ul>
<div class="longdesc" id="entry-longdesc">
<p>
<code>.context</code>属性在jQuery 1.10中已经过时，并且，仅为维持支持jQuery的迁移插件（ jQuery Migrate plugin）中得<code>.live()</code> 方法。它可能会在未来的版本中删除，恕不另行通知。</p>
<p>
<code>.live()</code>方法绑定事件处理器使用此属性，来检测将要使用的元素根节点以实现事件委派。（译者注：<code>.live()</code>方法 在jQuery 1.9中被移除）</p>
<p>这个属性的值通常等于文档<code>document</code>,因为如果没有提供这个属性，默认情况下文档document提供给jQuery对象。上下文可能会有所不同，例如，对象是通过一个<code>&lt;iframe&gt;</code>或XML文档内搜索的。</p>
<p>需要注意的是
			上下文属性可能只适用于通过<code>jQuery()</code>选择的原始元素，
			因为它是可以让用户将元素添加到集合中，比如通过<code>.add()</code>方法，
			 这些可以具有不同的上下文。</p>
</div>
<section class="entry-examples" id="entry-examples"><header><h2 class="underline">例子:</h2></header><div class="entry-example" id="example-0">
<h4><span class="desc">确定确切的上下文使用。</span></h4>
<div class="syntaxhighlighter xml ">
<table>
<tbody>
<tr>
<td class="gutter">
<div class="line n1">1</div>
<div class="line n2">2</div>
<div class="line n3">3</div>
<div class="line n4">4</div>
<div class="line n5">5</div>
<div class="line n6">6</div>
<div class="line n7">7</div>
<div class="line n8">8</div>
<div class="line n9">9</div>
<div class="line n10">10</div>
<div class="line n11">11</div>
<div class="line n12">12</div>
<div class="line n13">13</div>
<div class="line n14">14</div>
<div class="line n15">15</div>
<div class="line n16">16</div>
<div class="line n17">17</div>
<div class="line n18">18</div>
<div class="line n19">19</div>
<div class="line n20">20</div>
<div class="line n21">21</div>
</td>
<td class="code">
<pre><div class="container"><div class="line"><code><span class="doctype">&lt;!DOCTYPE html&gt;</span></code></div></div><div class="container"><div class="line"><code><span class="tag">&lt;<span class="title">html</span>&gt;</span></code></div></div><div class="container"><div class="line"><code><span class="tag">&lt;<span class="title">head</span>&gt;</span></code></div></div><div class="container"><div class="line"><code>  <span class="tag">&lt;<span class="title">style</span>&gt;</span><span class="css"></span></code></div></div><div class="container"><div class="line"><code>  <span class="tag">body</span> <span class="rules">{ <span class="rule"><span class="attribute">cursor</span>:<span class="value">pointer;</span></span> <span class="rule">}</span></span></code></div></div><div class="container"><div class="line"><code>  <span class="tag">div</span> <span class="rules">{ <span class="rule"><span class="attribute">width</span>:<span class="value"><span class="number">50</span>px;</span></span> <span class="rule"><span class="attribute">height</span>:<span class="value"><span class="number">30</span>px;</span></span> <span class="rule"><span class="attribute">margin</span>:<span class="value"><span class="number">5</span>px;</span></span> <span class="rule"><span class="attribute">float</span>:<span class="value">left;</span></span></span></code></div></div><div class="container"><div class="line"><code>        <span class="rule"><span class="attribute">background</span>:<span class="value">green;</span></span> <span class="rule">}</span></code></div></div><div class="container"><div class="line"><code>  <span class="tag">span</span> <span class="rules">{ <span class="rule"><span class="attribute">color</span>:<span class="value">red;</span></span> <span class="rule">}</span></span></code></div></div><div class="container"><div class="line"><code>  <span class="tag">&lt;/<span class="title">style</span>&gt;</span></code></div></div><div class="container"><div class="line"><code>  <span class="tag">&lt;<span class="title">script</span> <span class="attribute">src</span>=<span class="value">"https://code.jquery.com/jquery-latest.js"</span>&gt;</span><span class="javascript"></span><span class="tag">&lt;/<span class="title">script</span>&gt;</span></code></div></div><div class="container"><div class="line"><code><span class="tag">&lt;/<span class="title">head</span>&gt;</span></code></div></div><div class="container"><div class="line"><code><span class="tag">&lt;<span class="title">body</span>&gt;</span></code></div></div><div class="container"><div class="line"><code>  Context:<span class="tag">&lt;<span class="title">ul</span>&gt;</span><span class="tag">&lt;/<span class="title">ul</span>&gt;</span></code></div></div><div class="container"><div class="line"><code><span class="tag">&lt;<span class="title">script</span>&gt;</span><span class="javascript">$(<span class="string">"ul"</span>)</span></code></div></div><div class="container"><div class="line"><code>  .append(<span class="string">"&lt;li&gt;"</span> + $(<span class="string">"ul"</span>).context + <span class="string">"&lt;/li&gt;"</span>)</code></div></div><div class="container"><div class="line"><code>  .append(<span class="string">"&lt;li&gt;"</span> + $(<span class="string">"ul"</span>, document.body).context.nodeName + <span class="string">"&lt;/li&gt;"</span>);</code></div></div><div class="container"><div class="line"><code> </code></div></div><div class="container"><div class="line"><code><span class="tag">&lt;/<span class="title">script</span>&gt;</span></code></div></div><div class="container"><div class="line"><code> </code></div></div><div class="container"><div class="line"><code><span class="tag">&lt;/<span class="title">body</span>&gt;</span></code></div></div><div class="container"><div class="line"><code><span class="tag">&lt;/<span class="title">html</span>&gt;</span></code></div></div></pre>
</td>
</tr>
</tbody>
</table>
</div>
<h4>Demo:</h4>
<div class="demo code-demo"></div>
</div></section>
</div></article> </div>
</article>